from django.db import models


class LaboratoryMember(models.Model):
    true_name = models.CharField(verbose_name='成员真实姓名', max_length=20)
    school_number = models.CharField(verbose_name='学号', max_length=13)
    year = models.IntegerField(verbose_name='多少届')
    flag = models.IntegerField(verbose_name='是否注册', default=0)

    class Meta:
        db_table = 'laboratory_member'
        verbose_name = "实验室成员"
        verbose_name_plural = verbose_name


class User(models.Model):
    username = models.CharField(verbose_name='用户名', max_length=40)
    password = models.CharField(verbose_name='密码', max_length=40)
    qq_number = models.CharField(verbose_name='QQ号', max_length=15)
    true_name = models.CharField(verbose_name='真实姓名', max_length=20)
    about_me = models.CharField(verbose_name='关于我', max_length=100, blank=True)
    avatar = models.ImageField(verbose_name='头像', blank=True)
    information = models.CharField(verbose_name='个人信息', max_length=200, blank=True)

    class Meta:
        db_table = 'user'
        verbose_name = "用户"
        verbose_name_plural = verbose_name


class PublishBlog(models.Model):
    group_id = models.IntegerField(verbose_name='博客方向id', default=0)
    subject_id = models.IntegerField(verbose_name='博客类型id', default=0)
    title = models.CharField(verbose_name='博客标题', max_length=60)
    context = models.CharField(verbose_name='正文', max_length=1000)
    author = models.CharField(verbose_name='博客作者', max_length=40)
    time = models.DateTimeField(verbose_name='上传时间', auto_now_add=True)

    class Meta:
        db_table = 'publish_blog'
        verbose_name = "博客"
        verbose_name_plural = verbose_name
        ordering = ['-time']

    def __str__(self):
        return "<PublishBlog: %s>" % self.title


class Groups(models.Model):
    group_id = models.IntegerField(verbose_name='组别id')
    group_name = models.CharField(verbose_name='组名', max_length=15)

    class Meta:
        db_table = 'groups'
        verbose_name = "分组"
        verbose_name_plural = verbose_name
        ordering = ['group_id']


class Subject(models.Model):
    subject_id = models.IntegerField(verbose_name='方向id')
    subject_name = models.CharField(verbose_name='方向', max_length=15)

    class Meta:
        db_table = 'subject'
        verbose_name = "方向"
        verbose_name_plural = verbose_name


class Announcement(models.Model):
    content = models.CharField(verbose_name='公告内容', max_length=500)
    title = models.CharField(verbose_name='公告标题', max_length=50)
    time = models.DateTimeField()
    author = models.CharField(verbose_name='发起人', max_length=20)

    class Meta:
        verbose_name = "公告"
        verbose_name_plural = verbose_name


class Question(models.Model):
    title = models.CharField(verbose_name='问答标题', max_length=30)
    content = models.CharField(verbose_name='问题描述', max_length=200)
    time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    group_id = models.IntegerField(verbose_name='组id')
    author = models.IntegerField(verbose_name='作者id')


class QuestionAnswer(models.Model):
    question_id = models.IntegerField(verbose_name='问题id')
    user_id = models.IntegerField(verbose_name='用户id')
    content = models.CharField(verbose_name='回答内容', max_length=100)
    thank = models.IntegerField(verbose_name='是否被采纳', default=0)
    time = models.DateTimeField(verbose_name='回答时间', auto_now_add=True)


class AnswerReply(models.Model):
    answer_id = models.IntegerField(verbose_name='回答id')
    user_id = models.IntegerField(verbose_name='用户id')
    content = models.CharField('回复内容', max_length=300)
    time = models.DateTimeField('回复时间', auto_now_add=True)


class Collection(models.Model):
    answer_id = models.IntegerField(verbose_name='回答id')
    user_id = models.IntegerField(verbose_name='用户id')
    question_id = models.IntegerField(verbose_name='问题id')
